class Valleyers::Show::TransitCargos::Show::PostsController < ApplicationController
  def new
    @valleyer = Valleyer.find params[:valleyer_id]
    @post = Post.new :post_session_id => params[:post_session_id],
      :reship_id => params[:reship_id],
      :created_by_valleyer_id => current_valleyer_id
  end

  def create
    @post = Post.new params[:post]
    if @post.post_session.nil?
      @post.post_session = PostSession.new :reship_id => params[:post][:reship_id],
        :created_by_valleyer_id => current_valleyer_id
      @post.post_session.save
    else
      @post.reship_id = @post.post_session.reship_id
    end
    @post.save
    @valleyer = @post.reship.author
    @reships = Reship.paginate_by_author_id @valleyer.id,
      :page => params[:page_number],
      :per_page => 5,
      :order => "created_at desc"
  end
end
